// 笔试强训day33:包含不超过两种字符的最长子串

#include <iostream>
using namespace std;

int main() {
    string str; cin >> str;
    int count = 0, left = 0, right = 1, maxlen = 0, n = str.size();
    while(right < n)
    {
        if(str[right] != str[right - 1])
            count++;
        if(count == 2)
        {
            maxlen = max(maxlen, right - left);
            left++;
            while(str[left] == str[left - 1]) left++;
            count--;
        }
        right++;
    }
    maxlen = max(maxlen, right - left);
    cout << maxlen << endl;
}